﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CONEK911Manager.DAO;
using CONEK911Manager.DTO;

namespace CONEK911Manager.BUS
{
    class DistrictBUS
    {
        readonly DistrictDAO _districtDao = new DistrictDAO();
        public bool AddDistrict(DistrictDTO district)
        {
            return _districtDao.AddDistrict(district);
        }
        public List<DistrictDTO> GetAllDistrict()
        {
            var wardBus = new WardBUS();
            var listWard = wardBus.GetAllWard();
            var listDistrict = _districtDao.GetAllDistrict();
            foreach (var district in listDistrict)
            {
                var index = 0;
                var listWardOfDistrict = new List<WardDTO>();
                while (index < listWard.Count)
                {
                    if (district.DistrictId == listWard[index].DistrictId)
                    {
                        listWardOfDistrict.Add(listWard[index]);
                        listWard.RemoveAt(index);
                    } else
                    {
                        index++;
                    }
                }
                district.ListWard = listWardOfDistrict;
            }
            return listDistrict;
        }
    }
}
